<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="用户账户" clearable></el-input>
      </el-form-item>
      <!-- <el-form-item>
      <el-select v-model="dataForm.province" placeholder="请选择省" @change="provinceChanged" clearable>
        <el-option
          v-for="item in this.provinceList"
          :key="item.id"
          :label="item.areaName"
          :value="item.id">
        </el-option>
      </el-select>
      </el-form-item>
      <el-form-item class="page-form-item">
      <el-select v-model="dataForm.city" placeholder="请选择市" @change="provinceChanged1" v-if="this.cityType == 1" clearable>
        <el-option
          v-for="item in this.cityList"
          :key="item.id"
          :label="item.areaName"
          :value="item.id">
        </el-option>
      </el-select>
      </el-form-item>
      <el-form-item class="page-form-item">
      <el-select v-model="dataForm.area" placeholder="请选择区" v-if="this.areaType == 1" clearable>
        <el-option
          v-for="item in this.areaList"
          :key="item.id"
          :label="item.areaName"
          :value="item.id">
        </el-option>
      </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        prop="addTime"
        header-align="center"
        align="center"
        width="160"
        label="注册时间">
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="用户账户">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="用户名称">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="用户类型">
        <template slot-scope="scope">
          <span>
             {{scope.row.userType == 1 ? '区域运营商'
               :scope.row.userType == 2 ? '普通联盟店'
               :scope.row.userType == 3 ? '消费者'
               :scope.row.userType == 4 ? 'VIP会员'
               :scope.row.userType == 5 ? '中级版联盟店'
               :scope.row.userType == 6 ?'高级版联盟店'
               :scope.row.userType == 7 ?'城市合伙人'
               :scope.row.userType == 8 ? '城市合伙人联盟店':'未知'}}
           </span>   
        </template>
      </el-table-column>
      <el-table-column
        prop="paUserName"
        header-align="center"
        align="center"
        label="上级账户">
      </el-table-column>
      <el-table-column
        prop="paTrueName"
        header-align="center"
        align="center"
        label="上级名称">
      </el-table-column>
      <el-table-column
        prop="paUserType"
        header-align="center"
        align="center"
        label="上级类型">
        <template slot-scope="scope">
          <span>
             {{scope.row.userType == 1 ? '区域运营商'
               :scope.row.userType == 2 ? '普通联盟店'
               :scope.row.userType == 3 ? '消费者'
               :scope.row.userType == 4 ? 'VIP会员'
               :scope.row.userType == 5 ? '中级版联盟店'
               :scope.row.userType == 6 ?'高级版联盟店'
               :scope.row.userType == 7 ?'城市合伙人'
               :scope.row.userType == 8 ? '城市合伙人联盟店':'未知'}}
           </span>   
        </template> 
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from '../finance/finance-add-or-update'
export default {
  data () {
    return {
      dataForm: {
        keywords: '',
        province: '',
        city: '',
        area: '',
        startTime: '',
        endTime: '',
        userType: '',
        count: 0
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      provinceList: [],
      cityList: [],
      areaList: [],
      cityType: 0,
      areaType: 0
    }
  },
  components: {
    AddOrUpdate
  },
  activated () {
    this.getDataList()
  },
  methods: {
      // 获取数据列表
    getDataList (province, city, area, startTime, endTime, userType, keywords) {
      debugger
      if (userType !== undefined) {
        if (this.dataForm.userType !== userType) {
          this.dataForm.province = province
          this.dataForm.city = city
          this.dataForm.area = area
          this.dataForm.startTime = startTime
          this.dataForm.endTime = endTime
          this.dataForm.userType = userType
          this.dataForm.count = 1
          this.pageIndex = 1
          this.dataForm.keywords = keywords
        }
      }
      // if (this.dataForm.count === 0 || this.dataForm.userType !== userType && userType !== undefined) {
      //   this.dataForm.province = province
      //   this.dataForm.city = city
      //   this.dataForm.area = area
      //   this.dataForm.startTime = startTime
      //   this.dataForm.endTime = endTime
      //   this.dataForm.userType = userType
      //   this.dataForm.count = 1
      // }
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/member/area/queryProvinceList'),
        method: 'post'
      }).then(({data}) => {
        this.provinceList = data.data
      })
      this.$http({
        url: this.$http.adornUrl('/statistics/queryMembershipLower'),
        method: 'post',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'province': this.dataForm.province,
          'city': this.dataForm.city,
          'area': this.dataForm.area,
          'keywords': this.dataForm.keywords,
          'startTime': this.dataForm.startTime,
          'endTime': this.dataForm.endTime,
          'userType': this.dataForm.userType
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list
          this.totalPage = data.data.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    provinceChanged (id) {
      this.$http({
        url: this.$http.adornUrl('/member/area/querySubordinateList'),
        method: 'post',
        data: this.$http.adornData(id, false)
      }).then(({data}) => {
        this.cityList = data.data
        this.cityType = 1
        this.areaType = 0
        this.dataForm.city = ''
      })
    },
    provinceChanged1 (id) {
      this.$http({
        url: this.$http.adornUrl('/member/area/querySubordinateList'),
        method: 'post',
        data: this.$http.adornData(id, false)
      }).then(({data}) => {
        this.areaList = data.data
        this.areaType = 1
        this.dataForm.area = ''
      })
    },
      // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
      // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
      // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
      // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    }
  }
}
</script>
